﻿using System;
using System.Web.UI;
using Business;

public partial class Controls_BackEnd_ChangePassword : UserControl
{




    /// <summary>
    /// 
    /// </summary>
    private void ChangePass()
    {
        txtOldPass.Attributes.Add("value", txtOldPass.Text);
        txtNewpass.Attributes.Add("value", txtNewpass.Text);
        txtRepass.Attributes.Add("value", txtRepass.Text);
        var user = new Users { UserID = Config.UserId }.Users_GetByUserID();
        if (Business.Security.Security.MD5Encrypt(txtOldPass.Text.Trim()) != user.Password)
        {
            txtOldPass.Focus();
            txtOldPass.Attributes.Add("class", "inp-form-error");
            Config.Message(Page, Resources.Resource.OldPassInvalid, Resources.Resource.Warning);
            return;
        }
        if (txtNewpass.Text.Trim() != txtRepass.Text.Trim())
        {
            txtRepass.Focus();
            txtRepass.Attributes.Add("class", "inp-form-error");
            Config.Message(Page, Resources.Resource.NewPassInvalid, Resources.Resource.Warning);
            return;
        }     
        user.Password = Business.Security.Security.MD5Encrypt(txtNewpass.Text.Trim());
        user.ChangePassword();
        Config.Message(Page, Resources.Resource.ChangePassSuccess, Resources.Resource.Messenger);

    }




    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AllCommand(object sender, EventArgs e)
    {
        switch (((Control)sender).ID)
        {
            case "btnSave":
                ChangePass();
                break;

        }

    }
}
